package gs.eisenhower.swallet.ui_component;

import gs.eisenhower.swallet.R;
import gs.eisenhower.swallet.factory.FragmentFactory;
import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.ActionBar.TabListener;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.os.Bundle;

public class MainActivity extends Activity implements TabListener {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		ActionBar actionBar = getActionBar();
		actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

	    ActionBar.Tab expendituresTab = actionBar.newTab();
	    ActionBar.Tab earningsTab = actionBar.newTab();
	    ActionBar.Tab reportsTab = actionBar.newTab();
	    ActionBar.Tab historyTab = actionBar.newTab();
	    
	    expendituresTab.setText("Expenditures");
	    earningsTab.setText("Earnings");
	    reportsTab.setText("Reports");
	    historyTab.setText("History");
	    
	    expendituresTab.setTabListener(this);
	    earningsTab.setTabListener(this);
	    reportsTab.setTabListener(this);
	    historyTab.setTabListener(this);
	    
	    actionBar.addTab(expendituresTab);
	    actionBar.addTab(earningsTab);
	    actionBar.addTab(reportsTab);
	    actionBar.addTab(historyTab);
	}

	@Override
	public void onTabReselected(Tab tab, FragmentTransaction ft) {
		// TODO Auto-generated method stub
	}

	@Override
	public void onTabSelected(Tab tab, FragmentTransaction ft) {		
		Fragment fragment = FragmentFactory.getInstance().getFragment(tab.getPosition());
		ft.replace(android.R.id.content, fragment);
	}

	@Override
	public void onTabUnselected(Tab tab, FragmentTransaction ft) {
		// TODO Auto-generated method stub
	}
}
